
//封装api接口
const API_HOST = 'http://localhost:3000' //接口前缀
const ReqClient = (url, method, data) => {
    return new Promise((resolve, reject) => {
        if (method === 'GET') {
            var header = {
                'content-type': "application/x-www-form-urlencoded"
            }
        } else if (method === 'POST') {
            var header = {
                'content-type': 'application/json'
            }
        }
        wx.request({
            url: API_HOST + url,
            data,
            method,
            header: header,
            timeout: 6000,
            success: (res) => {
                resolve(res.data)
            },
            fail: (err) => {
                reject(err);
            },

        })
    })
}


//请求接口

//discovery下的发布的上传接口
//提交动态
export const submit = (data) => {
    return ReqClient('/discover-sub', 'POST', {
        ...data
    })
}
//获取动态
export const getDraft = () => {
    return ReqClient('/getDraft', 'GET')
}

//获取用户
export const getUser = (data) => {
    return ReqClient('/discovery/getuser', 'GET', {
        ...data
    })
}

//将评论发送会数据库存储
export const upDis =(data)=>{
    return ReqClient('/discovery/upDiscuss','POST',{
        ...data
    })
}


//获取发现——点赞信息
export const getStar = () => {
    return ReqClient('/discovery/star', 'GET')
}

//添加点赞信息
export const upStar = (data) => {
    return ReqClient('/discovery/updstar', 'POST', {
        ...data
    })
}

//删除点赞信息
export const deStar = (data) => {
    return ReqClient('/discovery/destar', 'POST', {
        ...data
    })
}

//获取评论
export const getDis = (data)=>{
    return ReqClient('/discovery/getdiscuss','GET',{
        ...data
    })
}
//获取回复评论的评论
export const getDis2 = (data)=>{
    return ReqClient('/discovery/getdiscuss2','GET',{
        ...data
    })
}
//获取discovery查找内容
export const getSearch = (data)=>{
    return ReqClient('/discovery/dis-getsearch','GET',{
        ...data
    })
}






export const getDetails = (data) => {
    return ReqClient('/getdetails', 'POST', {
        ...data
    })
    
}
export const getImage = (data) => {
    return ReqClient('/recommend', 'GET', {
        ...data
    })
}

export const getMore = (data) => {
    return ReqClient('/getMore', 'POST', {
        ...data
    })
}

export const postAuthor = (data) => {
    return ReqClient('/authorDetail', 'POST', {
        ...data
    })
}